home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Pascal Super Library
/
Pascal Super Library (CW International)(1997).bin
/
DELPHI32
/
EDIT_UTL
/
EDITEXPT
/
UEXPERT.PAS
< prev
Wrap
Pascal/Delphi Source File
|
1996-09-02
|
16KB
|
332 lines
{*******************************************************************
* Copyright (c) 1996 Valentin Sanchez Izquierdo *
* CopyRight (c) 1996 ValClip Group *
* This Expert is FreeWare,use on your risk *
* Email: valemari@ctv.es *
* http://ourworld.compuserve.com/homepages/VSanchez *
* MODULO: IDE Editor Utility Expert *
* *
* DATE : 25/08/96 3:47:51 *
* *
* NOTE : Special Tanks from John Howe 100065.55@compuserve.com *
* for memSeparatorClick function. *
* *
* HISTORI: *
* *
* *
*******************************************************************}
{
My Terms
This product has been released into the public domain, FREE!
I want no money in return, and you are welcome to make as many copies,
and distribute them, as you like. However, I would appreciate some
feedback, especially bugs or imporovements that you think that I
should make.
}
unit UExpert;
interface
uses Windows, Forms,Controls, Menus, Dialogs, Classes, ToolIntf, EditIntf, ExptIntf, VirtIntf, SysUtils,
Messages, Graphics, StdCtrls;
type
{TEditHeaderExpert}
TEditHeaderExpert = class(TIExpert)
menEditExp: TIMenuItemIntf; // Menu Items
menEditSep: TIMenuItemIntf;
menSeparator: TIMenuItemIntf;
constructor Create; virtual;
destructor Destroy; override;
function GetName: string; override;
function GetStyle: TExpertStyle; override;
function GetState: TExpertState; override;
function GetIDString: string; override;
procedure memHeaderClick(Sender: TIMenuItemIntf);
procedure memSeparatorClick(Senfer: TIMenuItemIntf );
procedure Execute; override;
end;
function InitExpert(ToolServices: TIToolServices; Registerproc: TExpertRegisterproc; var Terminate: TExpertTerminateProc): Boolean; export; stdcall;
procedure Register;
var
expEdit: TEditHeaderExpert = NIL;
implementation
{TEditHeaderExpert}
//----------------------------------------------------------------------//
// Constructor and menu creation
constructor TEditHeaderExpert.Create;
var menMain: TIMainMenuIntf;
menViewWinList: TIMenuItemIntf;
menViewMenu: TIMenuItemIntf;
begin
inherited Create;
menMain:=ToolServices.GetMainMenu;
if Assigned(menMain) then
try
{Find parent menu }
menViewWinList:=menMain.FindMenuItem('EditObjectItem');
if Assigned(menViewWinList) then
try
menViewMenu:=menViewWinList.GetParent;
if Assigned(menViewMenu) then
try
// You customize the menu display Text in your idiom.
// in English: Insert Header
// Insert Separator
// see ^^^ Lines
menEditSep:=menViewMenu.InsertItem(menViewWinList.GetIndex+1, '-', 'EditExpSepa1', '', 0, 0, 0, [mfVisible], NIL);
menEditExp:=menViewMenu.InsertItem(menEditSep.GetIndex+1, 'I&nsertar Cabecera',
//^^^^^^^^^^^^^^^^^^^
'EditInsertarCabeceraItem', '', ShortCut(Ord('C'), [ssCtrl, ssAlt]), 0, 0, [mfEnabled, mfVisible], memHeaderClick);
menSeparator:=menViewMenu.InsertItem(menEditExp.GetIndex+1, 'Insertar &Separador',
//^^^^^^^^^^^^^^^^^
'EditSeparatorItem','', ShortCut( Ord('S'),[ssCtrl, ssAlt]), 0, 0, [mfEnabled, mfVisible], memSeparatorClick);
finally
menViewMenu.Free;
end;
finally
menViewWinList.Free;
end;
finally
menMain.Free;
end;
end;
//----------------------------------------------------------------------//
destructor TEditHeaderExpert.Destroy;
begin
menEditExp.Free; // Release memory
menEditSep.Free;
menSeparator.Free;
inherited Destroy;
end;
//----------------------------------------------------------------------//
// Header insertion
procedure TEditHeaderExpert.memHeaderClick(Sender: TIMenuItemIntf);
const
cr = chr(13)+chr(10);
var
mModule: TIModuleInterface;
mEdit: TIEditorInterface;
writer: TIEditWriter;
sActual: string;
sz: PChar;
HW: HWND;
begin
If Toolservices = nil then exit; // No toolservices, no can do
HW := FindWindow('TeditWindow',Nil); {Evitamos que no este abierto el editor}
if HW > 0 then begin
try
GetMem(sz,255);
sActual := ToolServices.GetCurrentFile; {Fichero actual en edicion}
mModule := ToolServices.GetModuleInterface( sActual ); {cojemos un interface para el modulo}
mEdit := mModule.GetEditorInterface; {Cojemos uninterface para el editor}
writer := mEdit.CreateWriter; {por fin a escribir}
// You customice the text for you use
StrPCopy(sz,' * FECHA: '+DateToStr( date)+ ' '+TimeToStr(Time)+' *'+cr);
writer.Insert('{*******************************************************************'+cr);
writer.Insert(' * Copyright (c) 1996 Valentin Sanchez Izquierdo *'+cr);
writer.Insert(' * CopyRight (c) 1996 ValClip Group *'+cr);
writer.Insert(' * *'+cr);
writer.Insert(' * MODULO: *'+cr);
writer.Insert(' * *'+cr);
writer.Insert(sz);
writer.Insert(' * *'+cr);
writer.Insert(' * NOTAS: *'+cr);
writer.Insert(' * *'+cr);
writer.Insert(' * *'+cr);
writer.Insert(' * HISTORIA: *'+cr);
writer.Insert(' * *'+cr);
writer.Insert(' * *'+cr);
writer.Insert(' *******************************************************************}'+cr);
finally
writer.free; {Liberamos recursos}
mEdit.Free;
mModule.Free;
FreeMem(sz);
end;
end;
end;
//----------------------------------------------------------------------//
// This function is created from John Howe 100065.55@compuserve.com
//----------------------------------------------------------------------//
procedure TEditHeaderExpert.memSeparatorClick(Senfer: TIMenuItemIntf );
Var
MoInt : TIModuleInterface; // module interface
EdInt : TIEditorInterface; // editor interface
EdView : TIEditView; // the editor view
EdWrit : TiEditWriter; // Edit Writer
EdRead : TIEditReader; // Edit Reader
Ep : TEditPos; // the editorposition
FName : String; // The File Name
Posn : Integer; // Position
Lf : array[0..1] of Char; // Local Buffer
Lines : Integer; // Local Line Counter
EdPos : Integer; // Current Position in Editor Buffer
Eof : Boolean; // True if at end of Edit Buffer
FoundIt : Boolean; // True if Line Found
Function ReadEditorLine : String; // Read a return a line from the Editor
Var
CharPos : Integer; // Current Position in the result string
Begin
SetLength(Result,1024); // Longest Line !!!!
CharPos := 1; // begin at the beginning
Repeat
Try
Eof := EdRead.GetText(EdPos,
@Result[CharPos],1) <> 1; // Read a character
Except // Exception trap
Begin
Eof := True; // Eof JIC
Result := ''; // No Result
end;
end;
Inc(EdPos); // Read one so increment the buffer position
If Result[CharPos] = #10 then begin // was it a LineFeed and if so...
Result[CharPos] := #0; // Null the last char
SetLength(Result,CharPos - 1); // set the length
Exit; // bye bye
end;
Until Eof; // repeat till end of file
Result := ''; // if we get here we are eof so ''
end;
Function GotoLine(LineNo : Integer) : Boolean; // Goto line from file start
Var
Lines : Integer; // Line count
Begin
Result := False; // assume failure
If LineNo = 1 then exit; // if first line we are there already
EdPos := 0; // zap editor pos
Lines := 1; // First line
While (NOT Result) do begin // while not done
Try
Eof := EdRead.GetText(EdPos,Lf,1) <> 1; // read a character
Except
Eof := True; // assume EOF on exception
end;
Inc(EdPos); // Bump Editor position
If Lf[0] = #10 then Inc(Lines); // if EOL then bump count
If Lines = LineNo then Begin // if this is the line we want
Eof := False; // not EOF
Result := True; // got it
end;
end;
End;
Begin
If Toolservices = nil then exit; // No toolservices, no can do
Fname := Toolservices.GetCurrentFile; // Get the file name
If Pos('.DFM',UpperCase(FName)) > 0 then begin // if this is a DFM
ShowMessage('Pascal source must have focus'); // Tell em not to be stupid
Exit; // Bye Bye
end;
if Not Toolservices.IsFileOpen(FName) then begin // if file is not open
If Not Toolservices.OpenFile(FName) then begin // try and open it
MessageDlg(Format('Can''t open %s',[FName]),
mtError,[mbOk],0); // tell em we failed
Exit; // bye bye
end;
end;
MoInt := Toolservices.GetModuleInterface(Fname); // get the module interface for the file
Try
EdInt := MoInt.GetEditorInterface; // get the editor interface
Try
EdView := EdInt.GetView(0); // get the view
Try
Ep := EdView.GetPos(0); // get the current cursor position
Finally
EdView.Free; // free the view
end;
EdRead := EdInt.CreateReader; // Create the Reader
Try
FoundIt := GotoLine(Ep.Line); // jump to the required line
Finally
EdRead.Free; // Free the buffer
end;
If Not FoundIt then exit; // bomb out if not found
EdWrit := EdInt.CreateWriter; // get the vWriter
Try
With EdWrit Do Begin // with the writer
CopyTo(EdPos); // move down to the first char of the line
Insert('//----------------------------------------------------------------------//'#13#10); // insert the debug stuff
end;
Finally
EdWrit.Free; // free the view
end;
Finally
EdInt.Free; // free the interface
end;
Finally
MoInt.Free; // free the module
End;
end;
//----------------------------------------------------------------------//
procedure TEditHeaderExpert.Execute;
begin
{nada}
end;
//----------------------------------------------------------------------//
function TEditHeaderExpert.GetName: String;
begin
Result:='Editor Expert';
end;
//----------------------------------------------------------------------//
function TEditHeaderExpert.GetStyle: TExpertStyle;
begin
Result:=esAddIn;
end;
//----------------------------------------------------------------------//
function TEditHeaderExpert.GetState: TExpertState;
begin
Result := [esEnabled]
end;
//----------------------------------------------------------------------//
function TEditHeaderExpert.GetIDString: String;
begin
Result:='ValCLip.EditExpert';
end;
//----------------------------------------------------------------------//
//Codigo de Registro
procedure Register;
begin
RegisterLibraryExpert(TEditHeaderExpert.Create);
end;
//----------------------------------------------------------------------//
procedure TerminateProc;
begin
end;
//----------------------------------------------------------------------//
// Standar init
function InitExpert(ToolServices: TIToolServices; Registerproc: TExpertRegisterproc; var Terminate: TExpertTerminateProc): Boolean; export; stdcall;
begin
Result:=ExptIntf.ToolServices=NIL;
if not Result then
exit;
ExptIntf.ToolServices:=ToolServices;
if Assigned(ToolServices) then
Application.Handle:=ToolServices.GetParentHandle;
Terminate:=NIL;
expEdit:=TEditHeaderExpert.Create;
RegisterProc(expEdit);
end;
end.